package com.sh.springbootinit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sh.springbootinit.common.BaseResponse;
import com.sh.springbootinit.common.ErrorCode;
import com.sh.springbootinit.common.ResultUtils;
import com.sh.springbootinit.exception.ThrowUtils;
import com.sh.springbootinit.model.dto.Picture.PictureQueryRequest;
import com.sh.springbootinit.model.entity.Picture;
import com.sh.springbootinit.service.impl.PictureServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 图片接口
 */
@RestController
@RequestMapping("/picture")
@Slf4j
public class PictureController {



    @Resource
    private PictureServiceImpl pictureService;

    // region

    /**
     * 创建
     * @return
     */
    @PostMapping("/list/page")
    public BaseResponse<Page<Picture>> listPictureByPage(@RequestBody PictureQueryRequest pictureQueryRequest, HttpServletRequest request) {
        int current = pictureQueryRequest.getCurrent();
        int pageSize = pictureQueryRequest.getPageSize();
        ThrowUtils.throwIf(pageSize>20, ErrorCode.PARAMS_ERROR,"pageSize不能超过20");
        Page<Picture> res = pictureService.searchPicture(pictureQueryRequest.getSearchText(), current, pageSize);
        return ResultUtils.success(res);
    }
    // endregion
}